package Chapter4;

import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	public PersonSortable(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}
	@Override
	public String toString() {
		return name +"-"+ age ;
	}
	public int compareTo(PersonSortable other)
	   {
	      if (this.name.compareTo(other.name)>0) return 1;
	      else if (this.name.compareTo(other.name)<0) return -1;
	      else {
	    	  if(this.age>other.age) return 1;
	    	  else if(this.age<other.age) return -1;
	    	  else
	    		  return 0;
	    		
	      }
	     
	   }

	
}
public class Main1{


public static void main(String[] args) {

    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    String name;
    int age;
    PersonSortable []p=new PersonSortable[n];
    for (int i = 0; i < n; i++) {
		name=sc.next();
		age=sc.nextInt();
		p[i]=new PersonSortable(name, age);	
	}
    Arrays.sort(p);
    for (int i = 0; i < p.length; i++) {
    	System.out.println(p[i]);
	}
    
    System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
    
}

}
